package com.xvyy.tingshu.order.service.impl;

import com.xvyy.tingshu.model.order.LocalMsg;
import com.xvyy.tingshu.order.mapper.LocalMsgMapper;
import com.xvyy.tingshu.order.mapper.OrderInfoMapper;
import com.xvyy.tingshu.order.service.MqOpsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * ClassName: MqOpsServiceImpl
 * Package: com.xvyy.tingshu.order.service.impl
 *
 * @Description:
 * @Author: xvyy
 * @Create: 2025/2/11 - 19:56
 * @Version: v1.0
 */
@Service
@Slf4j
public class OpsServiceImpl implements MqOpsService {

    @Autowired
    private LocalMsgMapper localMsgMapper;
    @Autowired
    private OrderInfoMapper orderInfoMapper;
    @Autowired
    private OrderInfoServiceImpl orderInfoService;

    @Override
    public void updateLocalMsg(String content) {
        LocalMsg localMsg = localMsgMapper.selectOne(new LambdaQueryWrapper<LocalMsg>().eq(LocalMsg::getMsgContent, content));
        if (localMsg != null) {
            localMsg.setStatus(1);
            localMsgMapper.updateById(localMsg);
        } else {
            System.out.println("未找到消息内容为 " + content + " 的本地消息");
        }
    }

    @Override
    public void cancelOrderStatus(String orderNo) {
        int count = orderInfoMapper.cancelOrderStatus(orderNo);
        log.info(count > 0 ? "订单状态更新成功" : "订单状态更新失败");
    }

    @Override
    public void updateOrderTypePaySuccess(String orderNo) {
        orderInfoService.paySuccess(orderNo);
    }
}
